<template>
  <!-- 工作组及对应结果 -->
  <div id="wL">
    <Splitpanes>
      <Pane size="65">
        <vxe-toolbar perfect>
          <template #buttons>
            <div class="smallToolTitle">
              检验主记录</div>
            <vxe-button type="text"
              class="button-blue"
              content="查询"
              @click="handleSearch"></vxe-button>
            <vxe-button type="text"
              class="button-blue"
              content="保存"
              @click="saveMany()"></vxe-button>
          </template>
        </vxe-toolbar>
        <div class="tableBody">
          <vxe-table ref="wLTable"
            class="mytable-scrollbar"
            border align="left"
            height="auto" :data="wL"
            :loading="showLoading"
            :cell-style="cellClassName"
            :row-config="{ isCurrent: true, isHover: true }"
            :column-config="{ resizable: true }"
            :keyboard-config="{ isArrow: true }"
            :sort-config="{ trigger: 'cell' }"
            @cell-click="wLRowClick"
            resizable show-overflow>
            <!-- <vxe-column type="checkbox"
              width="26"
              fixed="left"></vxe-column> -->
            <vxe-column type="seq"
              title="#" width="30"
              fixed="left"></vxe-column>
            <vxe-column field="isUrgent"
              width="16" align="center"
              fixed="left"
              class-name="flag-cell">
              <template #header>
                <span
                  style="font-weight: 150; font-size: 8px">急</span>
              </template>
              <template
                #default="{ row }">
                <span
                  class="el-icon-first-aid-kit"
                  v-if="row.isUrgent === 1">
                  <el-icon>
                    <WarnTriangleFilled />
                  </el-icon>
                </span>
              </template>
            </vxe-column>
            <vxe-column field="isPrint"
              width="16" align="center"
              fixed="left"
              class-name="flag-cell">
              <template #header>
                <span
                  style="font-weight: 150; font-size: 8px">打</span>
              </template>
              <template
                #default="{ row }">
                <i class="el-icon-printer"
                  v-if="row.isPrint === 1">
                  <el-icon>
                    <Printer />
                  </el-icon>
                </i>
              </template>
            </vxe-column>
            <vxe-column
              field="isAutoPrint"
              width="16" align="center"
              fixed="left"
              class-name="flag-cell">
              <template #header>
                <span
                  style="font-weight: 150; font-size: 8px">自</span>
              </template>
              <template
                #default="{ row }">
                <span
                  class="el-icon-s-platform"
                  v-if="row.isAutoPrint === 1">
                  <el-icon>
                    <Monitor />
                  </el-icon>
                </span>
              </template>
            </vxe-column>
            <vxe-column field="isChk"
              width="16" align="center"
              fixed="left"
              class-name="flag-cell">
              <template #header>
                <span
                  style="font-weight: 150; font-size: 8px">审</span>
              </template>
              <template
                #default="{ row }">
                <i v-if="row.isChk === 1"
                  class="el-icon-s-check">
                  <span
                    style="color: #fff">初</span>
                </i>
                <i v-else-if="row.isChk === 2 || row.isChk === 1"
                  class="el-icon-finished">
                  <el-icon>
                    <SuccessFilled />
                  </el-icon>
                </i>
              </template>
            </vxe-column>
            <vxe-column field="isAlarm"
              width="16" align="center"
              fixed="left"
              class-name="flag-cell">
              <template #header>
                <span
                  style="font-weight: 150; font-size: 8px">危</span>
              </template>
              <template
                #default="{ row }">
                <i class="el-icon-warning"
                  v-if="row.isAlarm === 1">
                  <el-icon>
                    <WarningFilled />
                  </el-icon>
                </i>
              </template>
            </vxe-column>
            <vxe-column field="sampleda"
              title="检验日期" width="80"
              sortable>
              <template
                #default="{ row }">
                <span>{{ row.sampleda }}</span>
              </template>
            </vxe-column>
            <vxe-column field="sampleNo"
              title="标本号" width="62"
              sortable>
              <template
                #default="{ row }">
                <span>{{ row.sampleNo }}</span>
              </template>
            </vxe-column>
            <vxe-column field="sampleNo"
              title="审核状态" width="75"
              sortable>
              <template
                #default="{ row }">
                <span
                  v-if="row.isChk === null || row.isChk === 0">未审核</span>
                <span
                  v-else-if="row.isChk === 1">初审</span>
                <span
                  v-else-if="row.isChk === 2">审核</span>
              </template>
            </vxe-column>
            <vxe-column field="reqNo"
              title="条码号" width="90"
              sortable>
              <template
                #default="{ row }">
                <span>{{ row.reqNo }}</span>
              </template>
            </vxe-column>
            <vxe-column field="patNa"
              title="姓名" width="70"
              sortable>
              <template
                #default="{ row }">
                <span>{{ row.patNa }}</span>
              </template>
            </vxe-column>
            <vxe-column field="patNo"
              title="病历号" width="128">
              <template
                #default="{ row }">
                <span>{{ row.patNo }}</span>
              </template>
            </vxe-column>
            <vxe-column
              field="patTypeNa"
              title="类型" width="50"
              sortable></vxe-column>
            <vxe-column
              field="reqDeptNa"
              title="科室" width="70"
              show-overflow></vxe-column>
            <vxe-column field="sex"
              title="性别" width="35"
              show-overflow>
              <template
                #default="{ row }">
                {{ getSexName(row) }}
              </template>
            </vxe-column>
            <vxe-column field="age"
              title="年龄" width="50"
              show-overflow></vxe-column>
            <vxe-column
              field="testPurpose"
              title="检验目的" width="170"
              show-overflow></vxe-column>
            <vxe-column field="bedNo"
              title="床号" width="60"
              show-overflow></vxe-column>
            <vxe-column
              field="sampleTypeNa"
              title="样本类型"
              min-width="100"
              show-overflow></vxe-column>
          </vxe-table>
        </div>
      </Pane>
      <Pane size="35">
        <vxe-toolbar perfect>
          <template #buttons>
            <div
              class="smallToolTitle inspeResultsTitle">
              检验结果</div>
          </template>
        </vxe-toolbar>
        <div class="tableRight">
          <vxe-table ref="wLResultTable"
            border align="left"
            resizable show-overflow
            height="auto"
            v-loading="loading"
            :data="wLResultList"
            :row-config="{ isCurrent: true, isHover: true }"
            :keyboard-config="{ isArrow: true }"
            :cell-style="calcCellBgColor">
            <vxe-column type="seq"
              title="#" width="30"
              fixed="left"></vxe-column>
            <vxe-column field="itemNo"
              title="检验项目"
              min-width="120">
              <template
                #default="{ row }">
                {{ `${row.itemNo} ${row.itemNa}` }}
              </template>
            </vxe-column>
            <vxe-column
              field="testResult"
              title="结果"
              width="80"></vxe-column>
            <vxe-column field="resultFlag" title="" width="40">
              <template #default="{ row }">
                <span class="padding-lr-xs text-df">{{ getResultFlag(row.resultFlag) }}</span>
                <span class="padding-lr-xs" v-if="row.isAlarm === '1' || row.isAlarm === 1">{{ row.alarmText }}</span>
              </template>
            </vxe-column>
            <vxe-column field="ref"
              title="参考范围"
              width="80"></vxe-column>
          </vxe-table>
        </div>
      </Pane>
    </Splitpanes>
  </div>
</template>
<script setup lang="ts">
// 引入组件区 ==========
import { reactive, ref, defineExpose, getCurrentInstance, onMounted } from 'vue';
import { VXETable } from 'vxe-table';
import { IsEmpty, formatDateTime ,sortByField} from '@/utils/common.ts';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage';
import { Splitpanes, Pane } from 'splitpanes';
import { getOptionValueByCodeRptGroupOption, getOptionValueByCodeGlobalOption } from '@/utils/SysOptionsHelper';
import { isEmpty } from 'lodash';

// 全局变量定义区 ==========
let { proxy }: any = getCurrentInstance();
let wL: any = reactive([]); //病人列表数据
let wLResultList: any = reactive([]); //项目列表数据
let patTypeList: any = reactive([]); //字典表：病人类型
let sexList: any = reactive([]); //字典表：性别
let form: any = reactive({});
let wLTable = ref(null);
let currentWkltRow: any = {};
let loading = ref(false); //刷新+表格加载
let showLoading = ref(false);
defineExpose({
  getWklt
});
let props = defineProps({
  itemDetailList: Array as () => any[]
}) as any;

// 方法定义区 =============
// 页面加载时字典
onMounted(() => {
  getDictDetailList(); //加载病人类型字典
  getDictSexList(); //加载性别字典
});
// 获取工作列表
function getWklt(formWklt) {
  showLoading.value=true;
  wL.length = 0; //放入数据前清空数据
  wLResultList.length = 0;
  //form = formWklt;
  Object.assign(form, formWklt);

  const url = '/lab/maininfo/findReviewedResutByLabMaininfo';
  const data = {
    wtId: form.selectWtId,
    rptGroup: form.wtId,
    scheduleDateBegin: IsEmpty(form.scheduleDate) ? '' : formatDateTime(form.scheduleDate, 'yyyy-MM-dd') + ' 00:00:00',
    scheduleDateEnd: IsEmpty(form.scheduleDate) ? '' : formatDateTime(form.scheduleDate, 'yyyy-MM-dd') + ' 23:59:59',
    visitTypeIds: form.visitTypeIds,
    specTypeIds: form.specTypeIds,
    sampleNo: form.sampleNo,
    isReviewed: IsEmpty(form.isReviewed) || form.isReviewed === 0 || form.isReviewed === '0' ? null : form.isReviewed, //是否审核
    isPrinted: IsEmpty(form.isPrinted) || form.isPrinted === 0 || form.isPrinted === '0' ? null : form.isPrinted, //是否打印
    isFilterNoResult: form.isFilterNoResult, //根据结果筛选
    isFilterNoSpecCode: form.isFilterNoSpecCode, //根据条码号筛选
    isFilterNoPatName: form.isFilterNoPatName, //根据病人姓名筛选
    customSorting: form.customSorting //打印顺序
  };
  proxy.$http
    .post(url, data)
    .then(async (res: any) => {
      wL.push(...res.data);
      // 获取筛查条件数组
      /*    getFilterColumn('visitTypeName');
        getFilterColumn('patDepName');
        getFilterColumn('sex');
        getFilterColumn('specTypeName');*/

      wLRowClick({ row: wL[0] });
      showLoading.value = false;
    })
    .catch((err: any) => {
      showLoading.value = false;
      VxeMessage(err, VxeNotifyType.error);
    });
}
// 行点击事件
function wLRowClick({ row }: any) {
  if (IsEmpty(row)) {
    wLResultList.length = 0;
    return;
  }
  (proxy.$refs.wLTable as any).setCurrentRow(row);
  currentWkltRow = row;
  getWkltResultList();
}
//从词典获取所有的病人类型
// 获取界面字段
function getDictDetailList() {
  patTypeList.length = 0;
  const url = '/api/sys/basDictDetail/findDictDetailList';
  proxy.$http
    .get(url, { params: { code: 'PATTYPE' } })
    .then((res: any) => {
      patTypeList.push(...res.data);
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
}
function getPatTypeName(row) {
  // proxy.$nextTick(() => {
  if (patTypeList.length > 0 && row.patType !== null) {
    const group = patTypeList.find((item) => item.code == row.patType);
    return group.name;
  }
}
//获取性别数据字典
function getDictSexList() {
  sexList.length = 0;
  const url = '/api/sys/basDictDetail/findDictDetailList';
  proxy.$http
    .get(url, { params: { code: 'SEX' } })
    .then((res: any) => {
      sexList.push(...res.data);
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
}
function getSexName(row) {
  // proxy.$nextTick(() => {
  if (sexList.length > 0 && row.sex !== null) {
    const group = sexList.find((item) => item.code == row.sex);
    if (isEmpty(group) || isEmpty(group.name)) {
      return '';
    }
    return group.name;
  }
}

/**查询 */
function handleSearch() {
  proxy.$emit('search');
}

// 获取检验结果
function getWkltResultList() {
  wLResultList.length = 0;
  loading.value = false;
  const url = '/lab/maininfo/findRptResultByLabMaininfo';
  const data = {
    id: currentWkltRow.id
  };
  proxy.$http
    .get(url, { params: data })
    .then(async (res: any) => {
      // wLResultList.push(...res.data);
      wLResultList.push(...sortByField(res.data, 'displayOrder', 'asc'));
    })
    .catch((err: any) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}
/**单元格样式
 *【1】是否启用系统选项颜色配置  encolorsetting
 *【1】急背景色  isurgentcolor
 *【2】打背景色  isprintcolor
 *【3】自助机打印背景色  isautoprintcolor
 *【4】审核背景色  ischkcolor
 *【5】危急值背景色  isalarmcolor
 *【6】门诊类型病人列表颜色  mzpattypecolor
 *【7】住院类型病人列表颜色  zypattypecolor
 *【8】急诊类型病人列表颜色  jzpattypecolor
 *【9】体检类型病人列表颜色  tjpattypecolor
 *【10】其他类型病人列表颜色  qtpattypecolor
 */
function cellClassName({ row, rowIndex, $rowIndex, column, columnIndex, $columnIndex }) {
  let patTypeColor = '';
  if (column && !IsEmpty(column.fixed)) {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      if (row && row.patType === '1') {
        //门诊
        const b = getOptionValueByCodeGlobalOption('mzpattypecolor');
        if (!IsEmpty(b)) {
          patTypeColor = b;
        }
      } else if (row && row.patType === '2') {
        //急诊
        const b = getOptionValueByCodeGlobalOption('jzpattypecolor');
        if (!IsEmpty(b)) {
          patTypeColor = b;
        }
      } else if (row && row.patType === '3') {
        //住院
        const b = getOptionValueByCodeGlobalOption('zypattypecolor');
        if (!IsEmpty(b)) {
          patTypeColor = b;
        }
      } else if (row && row.patType === '4') {
        //体检
        const b = getOptionValueByCodeGlobalOption('tjpattypecolor');
        if (!IsEmpty(b)) {
          patTypeColor = b;
        }
      } else {
        //其他
        if (!IsEmpty(row.patType)) {
          const b = getOptionValueByCodeGlobalOption('qtpattypecolor');
          if (!IsEmpty(b)) {
            patTypeColor = b;
          }
        }
      }
    }
  }
  if (column.property === 'isUrgent') {
    if (row.isUrgent === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('isurgentcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff', padding: '0', margin: '0' };
        }
      }
      return { background: '#FF0000', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column.property === 'isChk') {
    if (row.isChk === 2) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('ischkcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#008000', color: '#fff' };
    } else if (row.isChk === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('ischkcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#00FF00', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column.property === 'isAlarm') {
    if (row.isAlarm === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('isalarmcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#FF9900', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column.property === 'isAutoPrint') {
    if (row.isAutoPrint === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('isautoprintcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#800080', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column.property === 'isPrint') {
    if (row.isPrint === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('isprintcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#000080', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
}
function getResultFlag(val) {
  const a = getOptionValueByCodeRptGroupOption('zjmaccsxs');
  if (a === '1' || a === 1) {
    if (val === 'H') {
      const b = getOptionValueByCodeRptGroupOption('pgjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '↑';
    }
    if (val === 'L') {
      const b = getOptionValueByCodeRptGroupOption('pdjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '↓';
    }
    if (val === 'P') {
      const b = getOptionValueByCodeRptGroupOption('yxjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '+';
    }
    if (val === 'Q') {
      const b = getOptionValueByCodeRptGroupOption('ryxjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '±';
    }
    if (val === 'M') {
      const b = getOptionValueByCodeRptGroupOption('zcjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '';
    }
    if (val === 'E') {
      const b = getOptionValueByCodeRptGroupOption('cwjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '×';
    }
    if (val === 'N') {
      const b = getOptionValueByCodeRptGroupOption('nxjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '√';
    }
  }
  if (val === 'H') {
    return '↑';
  }
  if (val === 'L') {
    return '↓';
  }
  if (val === 'P') {
    return '+';
  }
  if (val === 'Q') {
    return '±';
  }
  if (val === 'N') {
    return '√';
  }
  if (val === 'E') {
    return '×';
  }
  if (val === 'M') {
    return '';
  }
  return '';
}
/**
 * 单元格背景颜色
 *【1】是否启用系统选项颜色配置  encolorsetting
 *【2】偏高结果颜色  hresultcolor
 *【3】偏低结果颜色  lresultcolor
 *【4】阳性结果颜色  presultcolor
 *【5】正常结果颜色  mresultcolor
 *【6】弱阳性结果颜包  qresultcolor
 *【7】错误结果颜色  errresultcolor
 *【8】阴性结果颜色  nresultcolor
 *【9】结果标志颜色显示方式 jgbzysxsfs (0:背景色  1:文字颜色)
 */
function calcCellBgColor({ row, rowIndex, $rowIndex, column, columnIndex, $columnIndex }) {
  /**偏高【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'H' && column && column.field === 'resultFlag') {
    //查询系统选项偏高显示颜色   背景色还是文字颜色
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('hresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#ff0000' };
  }
  /**偏高【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'H' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('hresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#ff0000', color: '#fff' };
  }

  /**偏低【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'L' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('lresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#0035ff' };
  }
  /**偏低【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'L' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('lresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#0035ff', color: '#fff' };
  }

  /**阳性【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'P' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('presultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#0035ff' };
  }
  /**阳性【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'P' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('presultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#0035ff', color: '#fff' };
  }

  /**弱阳性【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'Q' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('qresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#0035ee' };
  }
  /**弱阳性【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'Q' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('qresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#0035ee', color: '#fff' };
  }

  /**错误【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'E' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('errresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#800000' };
  }
  /**错误【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'E' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('errresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#800000', color: '#fff' };
  }

  /**正常【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'M' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('mresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#000' };
  }
  /**正常【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'M' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('mresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { color: '#000' };
  }

  /**阴性【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'N' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('nresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#000' };
  }
  /**阴性【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'N' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('nresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { color: '#000' };
  }

  /**危急值 颜色 */
  if (row && !IsEmpty(row.isAlarm) && row.isAlarm === 1 && column && column.field === 'itemNo') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    const b = getOptionValueByCodeGlobalOption('isalarmcolor');
    const d = getOptionValueByCodeGlobalOption('wjzyssfxswbjys');/**危急值颜色显示是否为背景颜色 wjzyssfxswbjys */
    if (a === 1 || a === '1') {
      if (!IsEmpty(b)) {
        if (d && (d === '1' || d === 1)) {
          return { background: b, color: '#fff' };
        } else {
          return { color: b };
        }
      }
    }
  }
}
async function saveMany() {
  const itemDetailList = props.itemDetailList;

  if (isEmpty(itemDetailList)) {
    VxeMessage('暂无需要保存的模板', VxeNotifyType.warning);
    return;
  }
  if (isEmpty(wL)) {
    VxeMessage('无检验记录', VxeNotifyType.warning);
    return;
  }
  const type = await VXETable.modal.confirm(`确定添加模板项目?`); /*不能改el  $confirm 回车事件冒泡你*/
  if (type !== 'confirm') {
    return;
  }
  const url = '/lab/maininfo/batchUpdateRptResultByTemplate';
  const obj: any = {};
  obj.detailList = itemDetailList;
  obj.idList = wL.map((item) => item.id);

  proxy.$http
    .post(url, obj)
    .then((res: any) => {
      VxeMessage('更新成功', VxeNotifyType.success);
      handleSearch();
    })
    .catch((err: any) => {
      VxeMessage('更新失败', VxeNotifyType.error);
    });
}
</script>
<style lang="scss" scoped>
#wL {
  height: 100%;
  // 附加按钮间距
  .button-blue,
  .button-red {
    margin: 5px 0 5px 5px;
  }
  .tableBody {
    height: calc(100% - 40px);
  }
  .inspeResultsTitle {
    height: 34px;
    line-height: 34px;
  }
  .tableRight {
    height: calc(100% - 40px);
  }
}
:deep(.flag-cell) {
  .vxe-cell {
    padding: 0 2px !important;
  }
}
</style>
